home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-27 | 1.6 KB | 42 lines | [TEXT/GEOL] |
- Item 9254241 26-April-90 13:17PDT
-
- From: DEREK White, Derek
-
- To: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- Sub: Value parameter polymorphism
-
- Somewhere along the line I got the impression that when you pass object by
- value, a temporary of the ACTUAL parameter type is created, the copy
- constructor of the ACTUAL type is called on the temp, and then the address of
- the temp is passed to the function. Then inside the function, all virtual
- functions would be called through the vtable. This would allow polymorphism
- for value parameters. But I tried an example, and CFront always created a a
- temp of the FORMAL parameter class, and called the FORMAL copy constructor.
- Furthermore, inside the function, virtual methods were called virtually, even
- though the function only gets parameters of the FORMAL type. Am I correct? If
- so, why does the function get called virtually?
-
- class TShape { /* copy contructor & virtual Draw func */ };
- class TRect : public TShape {/* copy contructor & virtual Draw func */};
-
- void valtest(TShape s)
- { s.Draw(); } // virtual call, even though "s" is ALWAYS a TShape
-
- main() {
- TRect realRect;
- TRect &aRect = realRect;
- TShape realShape;
- TShape &aShape = realShape;
-
- valtest(realRect); // make temp TShape with TShape(realRect)
- valtest(aRect); // make temp TShape with TShape(aRect)
- valtest(realShape); aRect
- valtest(aShape);
- }
-
- - Derek White
- ATG East/Columbia
-
-